import cv2
import sys
from datetime import datetime
import time

def take_photo(fn):
    # Initialize camera (0 is usually the built-in webcam)
    cap = cv2.VideoCapture(0)
    
    if not cap.isOpened():
        print("Error: Could not access webcam")
        sys.exit(1)

    for i in range(0, 10):
        # Wait a moment for the camera to initialize
        ret, frame = cap.read()
    
    if ret:
        # Save the image
        cv2.imwrite(fn, frame)
        print(f"Photo saved as {fn}")
    else:
        print("Error: Could not capture frame")
    
    # Release the camera
    cap.release()

if __name__ == "__main__":
    take_photo("tmp/photo.jpg")